#include "vm.h"
#include <stdlib.h>
#include <string.h>

//新建程序环境
CHRT_PROGRAM Chvm_New_Program()
{
    CHRT_PROGRAM program = (CHRT_PROGRAM)malloc(STRUCT_SIZE(CHRT_PROGRAM));
    program->MainCallFrame = null;
    program->Reg = (CHRT_REG)malloc(STRUCT_SIZE(CHRT_REG));
    return program;
}

//新建调用帧
CHRT_CALL_FRAME Chvm_New_CallFrame(CHRT_STACK prevs, CHRT_REG reg, int32 size)
{
    CHRT_CALL_FRAME cf = (CHRT_CALL_FRAME)malloc(STRUCT_SIZE(CHRT_CALL_FRAME));
    cf->PrevCodeAddress = prevs;
    cf->Reg = reg;
    cf->Stack = Chvm_New_Stack(size);
    memset(cf->Stack, 0, size * sizeof(CHRT_STACK_ELEM));
    return cf;
}